define(function () {
    return function (now) {
        //先读
        let goods = localStorage.getItem("goods") ? JSON.parse(localStorage.getItem("goods")) : [];
        //判断是否第一次存
        if (goods.length < 1) {
            //是直接存
            goods.push({
                id: now.parent().attr("id"),
                num: 1,
                status: "icon-gouxuankuang2"
            })
        } else {
            let i = 0;
            //不是第一次存判断是否重复
            const f = goods.some((val, idx) => {
                i = idx;
                return val.id === now.parent().attr("id")
            })
            if (f) {
                goods[i].num++
            } else {
                //不是直接插入
                goods.push({
                    id: now.parent().attr("id"),
                    num: 1,
                    status: "icon-gouxuankuang2"
                })
            }
        }
        //操作完数据后存回localstroage
        localStorage.setItem("goods", JSON.stringify(goods))
    }
});